home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / rain_for.swf / scripts / __Packages / smashing / Point.as < prev    next >
Encoding:
Text File  |  2010-04-12  |  4.0 KB  |  195 lines

  1. class smashing.Point
  2. {
  3.    var x;
  4.    var y;
  5.    function Point(x, y)
  6.    {
  7.       this.x = Number(x);
  8.       this.y = Number(y);
  9.    }
  10.    function get length()
  11.    {
  12.       return Math.sqrt(this.x * this.x + this.y * this.y);
  13.    }
  14.    function set length(newLength)
  15.    {
  16.       if(this.length != 0)
  17.       {
  18.          var _loc2_ = newLength / this.length;
  19.          this.x *= _loc2_;
  20.          this.y *= _loc2_;
  21.       }
  22.    }
  23.    function get lengthSqu()
  24.    {
  25.       return this.x * this.x + this.y * this.y;
  26.    }
  27.    function copy()
  28.    {
  29.       return new smashing.Point(this.x,this.y);
  30.    }
  31.    function addPoint(p)
  32.    {
  33.       return new smashing.Point(p.x + this.x,p.y + this.y);
  34.    }
  35.    function subtractPoint(p)
  36.    {
  37.       return new smashing.Point(this.x - p.x,this.y - p.y);
  38.    }
  39.    function addScalar(n)
  40.    {
  41.       return new smashing.Point(this.x + n,this.y + n);
  42.    }
  43.    function subtractScalar(n)
  44.    {
  45.       return new smashing.Point(this.x - n,this.y - n);
  46.    }
  47.    function addPointMe(p)
  48.    {
  49.       this.x += p.x;
  50.       this.y += p.y;
  51.    }
  52.    function subtractPointMe(p)
  53.    {
  54.       this.x -= p.x;
  55.       this.y -= p.y;
  56.    }
  57.    function addScalarMe(n)
  58.    {
  59.       this.x += n;
  60.       this.y += n;
  61.    }
  62.    function subtractScalarMe(n)
  63.    {
  64.       this.x -= n;
  65.       this.y -= n;
  66.    }
  67.    function multiply(nFactor)
  68.    {
  69.       var _loc2_ = this.copy();
  70.       _loc2_.x *= nFactor;
  71.       _loc2_.y *= nFactor;
  72.       return _loc2_;
  73.    }
  74.    function divide(n)
  75.    {
  76.       var _loc2_ = this.copy();
  77.       if(n == 0)
  78.       {
  79.          _loc2_.x = 0;
  80.          _loc2_.y = 0;
  81.          return undefined;
  82.       }
  83.       _loc2_.x /= n;
  84.       _loc2_.y /= n;
  85.       return _loc2_;
  86.    }
  87.    function multiplyMe(n)
  88.    {
  89.       this.x *= n;
  90.       this.y *= n;
  91.    }
  92.    function divideMe(n)
  93.    {
  94.       this.x /= n;
  95.       this.y /= n;
  96.    }
  97.    function dot(p)
  98.    {
  99.       return this.x * p.x + this.y * p.y;
  100.    }
  101.    function cross()
  102.    {
  103.       return new smashing.Point(this.y,- this.x);
  104.    }
  105.    function normalize()
  106.    {
  107.       if(!this.x && !this.y)
  108.       {
  109.          return undefined;
  110.       }
  111.       var _loc2_ = this.length;
  112.       return new smashing.Point(this.x / _loc2_,this.y / _loc2_);
  113.    }
  114.    function normalizeMe()
  115.    {
  116.       if(!this.x && !this.y)
  117.       {
  118.          return undefined;
  119.       }
  120.       var _loc2_ = this.length;
  121.       this.x /= _loc2_;
  122.       this.y /= _loc2_;
  123.    }
  124.    function reverse()
  125.    {
  126.       var _loc2_ = new smashing.Point(this.x * -1,this.y * -1);
  127.       return _loc2_;
  128.    }
  129.    function reverseMe()
  130.    {
  131.       this.x *= -1;
  132.       this.y *= -1;
  133.    }
  134.    function rotateMe(nRad)
  135.    {
  136.       var _loc2_ = Math.sin(nRad);
  137.       var _loc3_ = Math.cos(nRad);
  138.       if(_loc2_ > 1 || _loc2_ < -1)
  139.       {
  140.       }
  141.       if(_loc3_ > 1 || _loc3_ < -1)
  142.       {
  143.       }
  144.       this.x = this.x * _loc3_ + this.y * (- _loc2_);
  145.       this.y = this.x * _loc2_ + this.y * _loc3_;
  146.    }
  147.    function rotate(nRad)
  148.    {
  149.       var _loc2_ = Math.sin(nRad);
  150.       var _loc3_ = Math.cos(nRad);
  151.       if(_loc2_ > 1 || _loc2_ < -1)
  152.       {
  153.       }
  154.       if(_loc3_ > 1 || _loc3_ < -1)
  155.       {
  156.       }
  157.       return new smashing.Point(this.x * _loc3_ + this.y * (- _loc2_),this.x * _loc2_ + this.y * _loc3_);
  158.    }
  159.    function rotateSinCos(nSin, nCos)
  160.    {
  161.       this.x = this.x * nCos + this.y * (- nSin);
  162.       this.y = this.x * nSin + this.y * nCos;
  163.    }
  164.    function findCosine(vOther)
  165.    {
  166.       var _loc3_ = this.dot(vOther);
  167.       var _loc4_ = this.length * vOther.length;
  168.       var _loc2_ = _loc3_ / _loc4_;
  169.       return _loc2_;
  170.    }
  171.    function equals(p)
  172.    {
  173.       if(this.x == p.x && this.y == p.y)
  174.       {
  175.          return true;
  176.       }
  177.       return false;
  178.    }
  179.    function zero()
  180.    {
  181.       this.x = 0;
  182.       this.y = 0;
  183.    }
  184.    function distSqu(p)
  185.    {
  186.       var _loc3_ = p.x - this.x;
  187.       var _loc2_ = p.y - this.y;
  188.       return _loc3_ * _loc3_ + _loc2_ * _loc2_;
  189.    }
  190.    function toString()
  191.    {
  192.       return "Point (" + this.x + "," + this.y + ")";
  193.    }
  194. }
  195.